<template>
  <div>
    <van-nav-bar title="登录" left-text="返回" @click-left="$router.push('/app/index')" right-text="注册" left-arrow />
    <van-form>
      <van-field
        v-model="mobile"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="pwd"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
        @click="doLogin"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      mobile: "",
      pwd: "",
    };
  },
  methods: {
    doLogin() {
      if (this.mobile == "" || this.pwd == "") {
        this.$toast.fail("不可为空");
        return false;
      }
var fdata = new FormData();
fdata.append('mobile',this.mobile);
fdata.append('pwd',this.pwd);
this.$axios.post('https://api.it120.cc/small4/user/m/login?deviceId=007&deviceName=monkey',fdata).then(res=>{
    if (res.code == 0) {
        this.$toast.success("登录成功");
        this.$store.commit('login',res.data)
        this.$router.go(-1)
        
    }
})
    },
  },
};
</script>